package com.frejoys.admin.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.agent.AgentRoleSaveDto;
import com.frejoys.common.dto.agent.AgentRoleUpdateDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.agent.AgentRoleVo;
import com.frejoys.service.AgentRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "代理角色", description = "代理角色")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixAdmin)
@Authorization(Authority.Private)
public class AdminAgentRoleController {

    private final AgentRoleService agentRoleService;


    /**
     * 新增代理角色
     */
    @Operation(summary = "新增代理角色")
    @PostMapping("/agent/role/save")
    public Result saveAgentRole(@RequestBody @Validated AgentRoleSaveDto dto) {
        agentRoleService.saveAgentRole(dto);
        return Result.success();
    }

    /**
     * 修改代理角色
     */
    @Operation(summary = "修改代理角色")
    @PostMapping("/agent/role/update")
    public Result updateAgentRole(@RequestBody @Validated AgentRoleUpdateDto dto) {
        agentRoleService.updateAgentRole(dto);
        return Result.success();
    }

    /**
     * 后台查询代理角色
     */
    @Operation(summary = "后台查询代理角色")
    @PostMapping("/agent/role/list")
    public Result<List<AgentRoleVo>> searchAgentRoleList() {
        return Result.success(agentRoleService.searchAgentRoleList());
    }

}
